/*
 * @Description: your project
 * @Author: chaizhou
 * @Date: 2023-02-28 16:32:30
 * @LastEditTime: 2023-02-28 16:33:11
 */
import JSEncrypt from 'jsencrypt/bin/jsencrypt'
import profile from '@root/profile'
// 公钥
// let publicKey;

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = profile.rsaPublicKey

// 加载文件获取公钥
// getPkey().then((res) => {
//   const { success, data } = res || {};
//   if (success) publicKey = data;
// });

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

/* // 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
} */
